import axios from "axios"
import nprogress from "nprogress" //导入进度条
import "nprogress/nprogress.css"  //导入样式
import Store from "@/store/index.js"
const requests=axios.create({
    baseURL:"/api",
    timeout:5000, 
})

 //请求拦截器 在发请求之前可以做一些事情
requests.interceptors.request.use((config)=>{
 
  nprogress.start() //进度条开始
  if(Store.state.detail.uuid_token){
    config.headers.userTempId=Store.state.detail.uuid_token
  }
  if(Store.state.phone.token){
    config.headers.token=Store.state.phone.token
  }
  return config
})
//响应成功或失败做些什么事情
requests.interceptors.response.use(res=>{
  nprogress.done() //进度条结束
  return res.data
},(error)=>{
  console.log(error);
    alert("服务器繁忙")
})
export default requests;